<template>
  <div class="today">
    <div class="classify">
      <div>
        <span>分类</span>
        <div class="classify_item">
          <a
            :class="classifyId == 0 ? 'active' : ''"
            @click="checkClassify(0)"
          >全部</a>
          <a
          
            v-for="(item,index) in classify"
            :key="index"
            :class="classifyId == item.id ? 'active' : ''"
            @click="checkClassify(item)"
          >{{ item.cName }}</a>
        </div>
      </div>
    </div>
    <!-- <div class="classify">
      <div>
        <span> 地区</span>
        <div class="classify_item">
          <a
            :class="regionId == 0 ? 'active' : ''"
            @click="ArecheckClassify(0)"
          >全部</a>
          <a
            v-for="item in classifyare"
            :key="item.id"
            :class="regionId == item.id ? 'active' : ''"
            @click="ArecheckClassify(item)"
          >{{ item.cName }}</a>
        </div>
      </div>
    </div> -->
    <div class="sort">
      <div class="sortList">
        <div>排序:</div>
        <div
          v-for="item in areaData"
          :key="item.id"
          :class="item.isSelected ? 'active' : ''"
          @click="checkArea(item)"
        >
          {{ item.title }}
          <div 
            v-if="item.title === '价格' && item.isSelected " 
            class="areaIconbox"
          >
            <i 
              v-if="item.sorting === 1" 
              class="el-icon-top" 
            />
            <i
              v-if="item.sorting === 2" 
              class="el-icon-bottom" 
            />
          </div>
        </div>
      </div>
      <div class="search">
        <input
          v-model="keywords"
          type="text"
          placeholder="搜索你想要的商品"
          @keyup.13="searchThis"
        >
        <img
          src="../../assets/img/SS@2x.png"
          alt=""
          @click="searchThis"
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "SellCakesTop",
  props: {
    shopid: {
      type: String,
      default: ""
    },
  },
  data() {
    return {
      classIfyData: [],
      areaData: [
        {
          title: "默认",
          isSelected: true,
          id: 0,
          value: "iOrder",
        },
        {
          title: "价格",
          isSelected: false,
          id: 1,
          sorting: 0, // 价格排序： 1从低到高，不等于1则从高到低
          value: "fSalePrice",
        },
        {
          title: "上架时间",
          isSelected: false,
          id: 2,
          value: "sj",
        }
      ],
      classifyare: [{
        cName: "香港",
        id:11
      },{
        cName: "澳门",
        id:22
      },{
        cName: "台湾",
        id:33
      },{
        cName: "日韩",
        id:44
      },{
        cName: "欧洲",
        id:55
      },{
        cName: "美洲",
        id:66
      }],
      regionId: 0, // 地区id
      classifyId: 0, // 分类
      areaId: "", // 排序
      classify: [], // 分类数据
      page: 1,
      keywords: "", // 搜索
      PriceSorting: 0, // 价格排序，1 从低到高，2 从高到低 
    };
  },
  mounted() {
    this.getData(this.shopid)
  },

  methods: {
    // 获取分类
    getData(shop_id) {
      let data = {
        shop_id: shop_id
      }
      this.$api.commit.ShopCateGory(data).then((res) => {
        if (res.code == 1) {
          console.log('获取分类', res.data)
          this.classify = res.data;
        }
      });
    },
    // 点击分类切换
    checkClassify(checkClassify) {
      console.log('点击分类切换,', checkClassify)
       if (checkClassify !== 0) {
        this.classifyId = checkClassify.id;
        this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords, this.PriceSorting);
      } else {
        this.classifyId = 0;
        this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords, this.PriceSorting);
      }
      
    },
    // 点击地区切换
    ArecheckClassify(ArecheckClassify){
      if (ArecheckClassify !== 0) {
        this.regionId = ArecheckClassify.id;
        this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords,this.PriceSorting);
      } else {
        this.regionId = 0;
        this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords,this.PriceSorting);
      }
    },
    // 点击排序
    checkArea(item) {
      this.areaData.forEach((items) => {
        items.isSelected = false;
        if (items.id == item.id) {
          this.areaId = item.value;
          this.$set(items, "isSelected", true);
          if(items.title === '价格') {
            // 价格排序
            if(items.sorting === 0) {
              items.sorting = 1
            } else if(items.sorting === 1) {
              items.sorting = 2
            } else if(items.sorting === 2) {
              items.sorting = 1
            }
            this.PriceSorting = items.sorting // 价格排序，1 从低到高，2 从高到低 
            this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords, this.PriceSorting);
          } else {
            this.PriceSorting = 0
            console.log('222')
            this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords, this.PriceSorting);
          }
        }
      });
    },
    // 搜索
    searchThis() {
      this.$emit("RefreshHotList", this.classifyId, this.regionId, this.areaId, this.keywords, this.PriceSorting);
    },
  },
};
</script>

<style scoped lang="scss">
.today {
  padding: 0 16.19rem;
  margin: 2.19rem 0;
  display: flex;
  flex-direction: column;

  .classify {
    background-color: #fff;
    padding: 1.18rem 1.68rem;
    border-bottom: 1px solid #e9e9e9;

    > div {
      align-items: center;
      display: flex;
      flex-direction: row;

      > span {
        width: 4rem;
        height: 4rem;
        background: rgba(13, 13, 13, 1);
        border-radius: 50%;
        font-size: 1rem;
        font-family: Microsoft YaHei;
        font-weight: 400;
        display: block;
        text-align: center;
        line-height: 4rem;
        color: rgba(255, 255, 255, 1);
        margin-right: 2rem;
      }

      > .classify_item {
        a {
          color: #666666;
          font-size: 1rem;
          margin-right: 2rem;
          line-height: 1.5rem;
          cursor: pointer;

          &.active {
            color: #08c19d;
          }
        }
      }
    }
  }

  :-webkit-input-placeholder {
    /* WebKit browsers */
    color: #acacac;
    font-size: 0.88rem;
  }

  :-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: #acacac;
    font-size: 0.88rem;
  }

  :-ms-input-placeholder {
    /* Internet Explorer 10+ */
    color: #acacac;
    font-size: 0.88rem;
  }

  .sort {
    padding: 1.5rem 2rem;
    background: #fff;
    font-size: 1rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;

    .sortList {
      display: flex;
      div {
        display: flex;
        cursor: pointer;
        padding: 0 1rem;
        .areaIconbox{
          padding: 0;
        }
        &.active {
          color: #08c19d;
        }
      }
    }

    .search {
      float: right;
      width: 20.94rem;
      height: 2rem;
      border-bottom: 0.06rem solid #b6b6b6;
      position: relative;

      input {
        width: 18rem;
        height: 2rem;
        outline: none;
        border: none;
        font-size: 0.88rem;
        color: #acacac;
      }

      img {
        cursor: pointer;
        position: absolute;
        right: 1rem;
        top: 0.4rem;
        z-index: 10;
        width: 1.25rem;
        height: 1.25rem;
      }
    }
  }
}
</style>
